package com.demo.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.core.constants.HttpStatus;
import com.demo.core.enums.UserRoleEnum;
import com.demo.core.exception.BusinessException;
import com.demo.core.exception.ParameterException;
import com.demo.dao.PracticalAchievementDao;
import com.demo.dao.UserDao;
import com.demo.domain.PracticalAchievement;
import com.demo.domain.User;
import com.demo.domain.ro.AchievementSearchRequest;
import com.demo.service.FileService;
import com.demo.service.PracticalAchievementService;
import com.demo.utils.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class PracticalAchievementServiceImpl extends ServiceImpl<PracticalAchievementDao, PracticalAchievement> implements PracticalAchievementService {
    @Autowired
    private PracticalAchievementDao practicalAchievementDao;

    @Autowired
    private UserDao userDao;

    @Autowired
    FileService fileService;

    @Autowired
    private StringUtils stringUtils;

    /**
     * 获取当前类型的所有实践成果（有分页）
     *
     * @param type
     * @param current
     * @param size
     * @param uid
     * @return
     * @throws ParameterException
     * @throws Exception
     */
    @Override
    public Page<PracticalAchievement> getAllAchievement(int type, int current, int size, Long uid) throws ParameterException, Exception {
        if (uid == null || uid < 0l) {
            throw new ParameterException("未正确获取到uid");
        }
        if (current < 0 || size < 0 || type < 0 || type > 4) {
            throw new ParameterException("属性值错误");
        }
        //        得到当前用户信息确定账号类型
        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.eq(User::getUId, uid);
        User user = userDao.selectOne(userLambdaQueryWrapper);
        if (user != null) {
            LambdaQueryWrapper<PracticalAchievement> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            //            非管理员则限定其搜索范围
            if (user.getUType() != 3) {
                lambdaQueryWrapper.like(PracticalAchievement::getAdvisorId, uid).or().like(PracticalAchievement::getPossessorId, uid);
            }
            //            按成果类型搜索
            lambdaQueryWrapper.eq(PracticalAchievement::getType, type);
            //            查询
            Page<PracticalAchievement> page = new Page<>(current, size);
            practicalAchievementDao.selectPage(page, lambdaQueryWrapper);
            if (page != null) {
                List<PracticalAchievement> original = page.getRecords();
                original.stream().forEach(practicalAchievement -> {
                    practicalAchievement = transformPracticalAchievement(practicalAchievement);
                });
            }
            return page;
        }
        return null;
    }

    /**
     * 搜索实践成果
     *
     * @param searchRequest
     * @return
     * @throws Exception 当前搜索限制：
     *                   项目名/指导老师/项目持有者、uid、时间、类型、分页
     */
    @Override
    public Page searchAchievements(AchievementSearchRequest searchRequest) throws Exception {
        LambdaQueryWrapper<PracticalAchievement> wrapper = new LambdaQueryWrapper<>();
        //            从user表找到该用户，查看其用户类型
        LambdaQueryWrapper<User> userWrapper = new LambdaQueryWrapper<>();
        // 设置成果持有者的限制（自己看自己的成果）
        userWrapper.eq(User::getUId, searchRequest.getUid());
        User user = userDao.selectOne(userWrapper);
        //            sql语句：where ( uid限制 and ( 关键词限制 and/or 指导老师限制 and/or 项目持有人限制 ) )
        if (user != null && !UserRoleEnum.ADMIN.equalsValue(user.getUType())) {
            //最外层的uid搜索限制（跟where同级）!!!!
            wrapper.and(w -> {
                w.like(PracticalAchievement::getPossessorId, searchRequest.getUid())
                        .or().like(PracticalAchievement::getAdvisorId, searchRequest.getUid());
            });
        }
        // 项目等级
        List<String> levels = searchRequest.getLevels();
        if(CollUtil.isNotEmpty(levels)) {
            wrapper.and(w -> {
                levels.forEach(lvl -> w.or().eq(PracticalAchievement::getLevel, lvl));
            });
        }
        //跟uid的搜索条件限制同级
        wrapper.and(w -> {
            //搜索条件的第二级
            //设置搜索词的限制!!!!!
            String searchTitle = searchRequest.getSearchTitle();
            String searchKeyWord = searchRequest.getSearchKeyWord();
            if (StrUtil.isNotBlank(searchTitle)) {
                //搜索指导老师则搜索advisorName
                if (searchTitle.equals("指导老师")) {
                    w.like(PracticalAchievement::getAdvisorName, searchKeyWord);
                } else if (searchTitle.equals("项目持有者")) {
                    //搜索持有者则搜索possessorName或advisorName
                    w.and(ww -> {
                        ww.like(PracticalAchievement::getPossessorName, searchKeyWord)
                                .or().like(PracticalAchievement::getAdvisorName, searchKeyWord);
                    });
                } else {
                    //若搜索字段非持有者和指导老师，则搜索项目名字段
                    w.like(PracticalAchievement::getTitle, searchKeyWord);
                }
            }
            // 设置起止搜索时间的条件限制
            // AND,OR,NOT的拼接限制!!!!!
            String connection1 = searchRequest.getConnection1();
            LocalDate startDate = searchRequest.getStartDate();
            LocalDate endDate = searchRequest.getEndDate();
            boolean dateLimited = (startDate != null || endDate != null);
            if (dateLimited && StrUtil.isNotBlank(connection1)) {
                connection1 = connection1.toUpperCase();
                if (connection1.equals("AND")) {
                    w.and(ww -> {
                        ww.ge(startDate != null, PracticalAchievement::getAchieveTime, startDate)
                                .le(endDate != null, PracticalAchievement::getAchieveTime, endDate);
                    });
                } else if (connection1.equals("OR")) {
                    w.or(ww -> {
                        ww.ge(startDate != null, PracticalAchievement::getAchieveTime, startDate)
                                .le(endDate != null, PracticalAchievement::getAchieveTime, endDate);
                    });
                }
            }
            // 设置搜索的成果类型
            // AND,OR,NOT的拼接限制
            Integer type = searchRequest.getType();
            String connection2 = searchRequest.getConnection2();
            if (type != null && type >= 0 && type <= 3 && StrUtil.isNotBlank(connection2)) {
                connection2 = connection2.toUpperCase();
                if (connection2.equals("AND")) {
                    w.eq(PracticalAchievement::getType, type);
                } else if (connection2.equals("OR")) {
                    w.or().eq(PracticalAchievement::getType, type);
                }
            }
            w.last("1 = 1");
        });
        // 实现分页查询
        Page page = new Page<>();
        page.setCurrent(searchRequest.getCurrentPage());
        page.setSize(searchRequest.getPageSize());
        page = practicalAchievementDao.selectPage(page, wrapper);
        if (page != null) {
            List<PracticalAchievement> original = page.getRecords();
            original.stream().forEach(practicalAchievement -> {
                practicalAchievement = transformPracticalAchievement(practicalAchievement);
            });
        }
        return page;
    }


    /**
     * 得到某个实践成果（根据实践成果名）
     *
     * @param searchRequest
     * @return
     * @throws Exception
     */

    @Override
    public PracticalAchievement getAchievement(AchievementSearchRequest searchRequest) throws Exception {
        //验证uid和搜索词是否符合规范
        if (searchRequest != null && searchRequest.getUid() != null
                && searchRequest.getSearchKeyWord() != null
                && !searchRequest.getSearchKeyWord().equals("")) {
            //确定当前用户的身份
            LambdaQueryWrapper<User> userWrapper = new LambdaQueryWrapper<>();
            userWrapper.eq(User::getUId, searchRequest.getUid());
            User user = userDao.selectOne(userWrapper);
            if (user == null) {
                System.out.println("无账号为:" + searchRequest.getUid() + "的用户");
                return null;
            }
            LambdaQueryWrapper<PracticalAchievement> wrapper = new LambdaQueryWrapper<>();
            //得到搜索结果,准确搜索
            wrapper.eq(PracticalAchievement::getTitle, searchRequest.getSearchKeyWord());
            PracticalAchievement achievement = practicalAchievementDao.selectOne(wrapper);
            //若用户非管理员
            if (user.getUType() != null && user.getUType() != 3 && achievement != null) {
                //确定当前搜索的成果是否为该用户的实践成果
                return achievement.getPossessorId().contains(searchRequest.getUid() + "") ||
                        achievement.getAdvisorId().contains(searchRequest.getUid() + "") ?
                        achievement : null;
            }
            return achievement;
        }
        return null;
    }

    /**
     * 是否有权限下载实践成果
     *
     * @param uid
     * @param ids
     * @return
     */
    @Override
    public boolean isAchievementEmpty(Long uid, List<Long> ids) {
        if (uid != null) {
            User user = userDao.selectOne(new LambdaQueryWrapper<User>().eq(User::getUId, uid));
            if (user == null) {
                System.out.println("未找到ID为：" + uid + "的用户");
                return false;
            }
            if (ids != null) {
                for (Long achievementId : ids) {
                    PracticalAchievement achievement = practicalAchievementDao.selectOne(
                            new LambdaQueryWrapper<PracticalAchievement>().eq(PracticalAchievement::getId, achievementId)
                    );
                    if (user.getUType() != null && user.getUType() != 3 && achievement != null) {
                        boolean flag = achievement.getPossessorId().contains(uid + "") || achievement.getAdvisorId().contains(uid + "");
                        if (!flag) {
                            throw new BusinessException(HttpStatus.FORBIDDEN, "当前账户没有下载成就ID为：" + achievementId + "的文件的权限");
                        }
                    }
                }
            }
        }
        return true;
    }

    /**
     * 导出实践成果
     *
     * @param request
     * @param response
     * @param ids
     */
    @Override
    public void exportExcel(HttpServletRequest request, HttpServletResponse response, List<Long> ids) {
        try {
            List<PracticalAchievement> list = new ArrayList<>();
            for (Long id : ids) {
                PracticalAchievement pa = practicalAchievementDao.selectById(id);
                if (pa != null) {
                    list.add(pa);
                }
            }
            @SuppressWarnings("resource")
            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet sheet = wb.createSheet("实践成果表");
            HSSFRow row = null;
            int columnIndex = 0;
            row = sheet.createRow(0);
            row.setHeight((short) (22.50 * 20));
            row.createCell(columnIndex).setCellValue("序号");
            row.createCell(++columnIndex).setCellValue("成果名称");
            row.createCell(++columnIndex).setCellValue("持有者编号");
            row.createCell(++columnIndex).setCellValue("持有者姓名");
            row.createCell(++columnIndex).setCellValue("成果等级");
            row.createCell(++columnIndex).setCellValue("指导老师编号");
            row.createCell(++columnIndex).setCellValue("指导老师姓名");
            row.createCell(++columnIndex).setCellValue("成果获得时间");
            row.createCell(++columnIndex).setCellValue("成果简介");
            row.createCell(++columnIndex).setCellValue("成果类型");

            for (int i = 0; i < list.size(); i++) {
                row = sheet.createRow(i + 1);
                PracticalAchievement pa = list.get(i);
                if (pa != null) {
                    columnIndex = 0;
                    row.createCell(columnIndex).setCellValue(i + 1);
                    row.createCell(++columnIndex).setCellValue(pa.getTitle());
                    row.createCell(++columnIndex).setCellValue(pa.getPossessorId());
                    row.createCell(++columnIndex).setCellValue(pa.getPossessorName());
                    row.createCell(++columnIndex).setCellValue(pa.getLevel());
                    row.createCell(++columnIndex).setCellValue(pa.getAdvisorId());
                    row.createCell(++columnIndex).setCellValue(pa.getAdvisorName());
                    row.createCell(++columnIndex).setCellValue(pa.getAchieveTime());
                    row.createCell(++columnIndex).setCellValue(pa.getDescription());
                    int type = pa.getType();
                    String userType;
                    if (type == 0) {
                        userType = "竞赛";
                    } else if (type == 1) {
                        userType = "专利";
                    } else if (type == 2) {
                        userType = "软著";
                    } else if (type == 3) {
                        userType = "论文";
                    } else {
                        userType = "项目";
                    }
                    row.createCell(++columnIndex).setCellValue(userType);
                }
            }
            sheet.setDefaultRowHeight((short) (16.5 * 20));
            for (int i = 0; i <= 9; i++) {
                sheet.autoSizeColumn(i);
            }
            String title = "实践成果表";
            response.setHeader("Content-disposition", "attachment;fileName=" + URLEncoder.encode(title + ".xls", "UTF-8"));
            response.setContentType("application/octet-stream;charset=utf-8");
            OutputStream ouputStream = response.getOutputStream();
            wb.write(ouputStream);
            ouputStream.flush();
            ouputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

//    /**
//     * 新增实践成果
//     *
//     * @param practicalAchievement
//     * @return
//     * @throws Exception
//     */
//    @Override
//    public PracticalAchievement importAchievement(PracticalAchievement practicalAchievement) throws Exception {
//        System.out.println(practicalAchievement);
//        if (practicalAchievement == null) {
//            throw new NullPointerException("新增的实践成果为null");
//        }
//        // 根据项目名称检测项目是否重复
//        String title = practicalAchievement.getTitle();
//        Long count = this.lambdaQuery().eq(PracticalAchievement::getTitle, title).count();
//        if(count > 0) {
//            throw new BusinessException(HttpStatus.PARAMS_ERROR, "录入成果重复！");
//        }
//        if (practicalAchievement.isTeacherFlag() == true) {//当存在指导老师时，需要判断指导老师工号姓名是否为空
//            if (practicalAchievement.getTitle().isEmpty() ||
//                    practicalAchievement.getPossessorId().isEmpty() ||
//                    practicalAchievement.getPossessorName().isEmpty() ||
//                    practicalAchievement.getLevel().isEmpty() ||
//                    practicalAchievement.getAdvisorId().isEmpty() ||
//                    practicalAchievement.getAdvisorName().isEmpty() ||
//                    practicalAchievement.getAchieveTime() == null ||
//                    practicalAchievement.getDescription().isEmpty() ||
//                    practicalAchievement.getType() == null
//            ) {
//                throw new IllegalArgumentException("importAchievement的属性值未完全填写或者非法填写（指导老师存在）");
//            }
//        } else {//当不存在指导老师时
//            if (practicalAchievement.getTitle().isEmpty() ||
//                    practicalAchievement.getPossessorId().isEmpty() ||
//                    practicalAchievement.getPossessorName().isEmpty() ||
//                    practicalAchievement.getLevel().isEmpty() ||
//                    practicalAchievement.getAchieveTime() == null ||
//                    practicalAchievement.getDescription().isEmpty() ||
//                    practicalAchievement.getType() == null
//            ) {
//                throw new IllegalArgumentException("importAchievement的属性值未完全填写或者非法填写（指导老师不存在）");
//            }
//        }
//        int result =
//                practicalAchievementDao.insert(practicalAchievement);
//        if (result >= 0) {
//            System.out.println("新增实践成果信息成功");
//            return practicalAchievement;
//        }
//        return null;
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public boolean importAchievementAndFile(PracticalAchievement practicalAchievement, MultipartFile[] files) {
//        try {
//            //新增实践成果信息
//            practicalAchievement = this.importAchievement(practicalAchievement);
//            if (practicalAchievement == null) {
//                throw new NullPointerException(
//                        "新增实践成果信息失败");
//            }
//            Long paId = practicalAchievement.getId();
//            if (paId == null || files.length <= 0 || files[0].isEmpty()) {
//                throw new NullPointerException(
//                        "paid为空或上传的文件为空");
//            }
//            //上传实践成果文件
//            boolean uploadResult = fileService.uploadFile(files, paId);
//            return uploadResult;
//        } catch (Exception e) {
//            e.printStackTrace();
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//            return false;
//        }
//    }
    /**
     * 新增实践成果
     *
     * @param practicalAchievement
     * @return
     * @throws Exception
     */
    @Override
    public PracticalAchievement importAchievement(PracticalAchievement practicalAchievement) throws Exception {
        System.out.println(practicalAchievement);
        if (practicalAchievement == null) {
            throw new NullPointerException("新增的实践成果为null");
        }
        // 根据项目名称检测项目是否重复
        String title = practicalAchievement.getTitle();
        Long count = this.lambdaQuery().eq(PracticalAchievement::getTitle, title).count();
        if(count > 0) {
            throw new BusinessException(HttpStatus.PARAMS_ERROR, "录入成果重复！");
        }
        if (practicalAchievement.getTeacherFlag() == 1) {//当存在指导老师时，需要判断指导老师工号姓名是否为空
            if (practicalAchievement.getTitle().isEmpty() ||
                    practicalAchievement.getPossessorId().isEmpty() ||
                    practicalAchievement.getPossessorName().isEmpty() ||
                    practicalAchievement.getLevel().isEmpty() ||
                    practicalAchievement.getAdvisorId().isEmpty() ||
                    practicalAchievement.getAdvisorName().isEmpty() ||
                    practicalAchievement.getAchieveTime() == null ||
                    practicalAchievement.getDescription().isEmpty() ||
                    practicalAchievement.getType() == null
            ) {
                throw new IllegalArgumentException("importAchievement的属性值未完全填写或者非法填写（指导老师存在）");
            }
        } else {//当不存在指导老师时
            if (practicalAchievement.getTitle().isEmpty() ||
                    practicalAchievement.getPossessorId().isEmpty() ||
                    practicalAchievement.getPossessorName().isEmpty() ||
                    practicalAchievement.getLevel().isEmpty() ||
                    practicalAchievement.getAchieveTime() == null ||
                    practicalAchievement.getDescription().isEmpty() ||
                    practicalAchievement.getType() == null
            ) {
                throw new IllegalArgumentException("importAchievement的属性值未完全填写或者非法填写（指导老师不存在）");
            }
        }
        int result =
                practicalAchievementDao.insert(practicalAchievement);
        if (result >= 0) {
            System.out.println("新增实践成果信息成功");
            return practicalAchievement;
        }
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean importAchievementAndFile(PracticalAchievement practicalAchievement, MultipartFile[] files) {
        try {
            //新增实践成果信息
            practicalAchievement = this.importAchievement(practicalAchievement);
            if (practicalAchievement == null) {
                throw new NullPointerException(
                        "新增实践成果信息失败");
            }
            Long paId = practicalAchievement.getId();
            if (paId == null || files.length <= 0 || files[0].isEmpty()) {
                throw new NullPointerException(
                        "paid为空或上传的文件为空");
            }
            //上传实践成果文件
            boolean uploadResult = fileService.uploadFile(files, paId);
            return uploadResult;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return false;
        }
    }

    @Override
    public String getTitleById(long paid) {
        String title =
                practicalAchievementDao.getTitleByid(paid);
        return title;
    }

    @Override
    public List<PracticalAchievement> getAllByLevel(AchievementSearchRequest searchRequest, Long uid) {
        // 仅 成员/管理员 可见
        LambdaQueryWrapper<User> userWrapper = new LambdaQueryWrapper<>();
        userWrapper.eq(User::getUId, searchRequest.getUid());
        User user = userDao.selectOne(userWrapper);
        LambdaQueryWrapper<PracticalAchievement> wrapper = new LambdaQueryWrapper<>();
        if (user != null && !UserRoleEnum.ADMIN.equalsValue(user.getUType())) {
            //最外层的uid搜索限制（跟where同级）!!!!
            wrapper.and(w -> {
                w.like(PracticalAchievement::getPossessorId, searchRequest.getUid())
                        .or().like(PracticalAchievement::getAdvisorId, searchRequest.getUid());
            });
        }
        // 项目等级
        List<String> levels = searchRequest.getLevels();
        if(CollUtil.isEmpty(levels)) {
            throw new BusinessException(HttpStatus.PARAMS_ERROR, "请选择项目等级！");
        }
        wrapper.and(w -> {
            levels.forEach(lvl -> w.or().eq(PracticalAchievement::getLevel, lvl));
        });
        return this.list(wrapper).stream().map(this::transformPracticalAchievement).collect(Collectors.toList());
    }

    @Override
    public List<PracticalAchievement> selectPracticalAchievementList(PracticalAchievement practicalAchievement) throws ParameterException {
        List<PracticalAchievement> practicalAchievementList = new ArrayList<>();
        if(practicalAchievement.getTitle() != null || practicalAchievement.getAdvisorName() != null || practicalAchievement.getPossessorName()!=null) {
            practicalAchievementList =
                    practicalAchievementDao.selectPracticalAchievementList(practicalAchievement.getTitle(),
                            practicalAchievement.getPossessorName(),practicalAchievement.getAdvisorName());
        }
        return practicalAchievementList;
    }

    @Override
    public List<PracticalAchievement> listAllPracticalAchievement() {
        List<PracticalAchievement> practicalAchievementList = practicalAchievementDao.listAllPracticalAchievement();
        return practicalAchievementList;
    }

    /**
     * 修改实践成果（未修改文件）
     * @param practicalAchievement
     * @return
     * @throws ParameterException
     */
    @Override
    public Integer updatePracticalAchievement(PracticalAchievement practicalAchievement) throws ParameterException {
        int row = 0;
        if(practicalAchievement.getId()!=null && practicalAchievement.getTitle()!=null && practicalAchievement.getPossessorId()!=null && practicalAchievement.getPossessorName()!=null && practicalAchievement.getLevel()!= null && practicalAchievement.getAdvisorId()!= null && practicalAchievement.getAdvisorName()!= null && practicalAchievement.getAchieveTime()!= null && practicalAchievement.getDescription()!= null && practicalAchievement.getType()!= null && practicalAchievement.getTeacherFlag()!= null &&  practicalAchievement.getDelFlag() == 0){
            row = practicalAchievementDao.updateById(practicalAchievement);
        }else{
            return null;
        }
        return row;
    }

    @Override
    public Integer deletePracticalAchievementById(PracticalAchievement practicalAchievement) throws ParameterException {
        int row = 0;
        if(practicalAchievement.getId()!=null){
            row = practicalAchievementDao.deletePracticalAchievementById(practicalAchievement);
        }
        return row;
    }


    /**
     * 整个practicalAchievement的possessorId、possessorName、advisorId、advisorName改格式
     *
     * @param practicalAchievement
     * @return
     */
    public PracticalAchievement transformPracticalAchievement(PracticalAchievement practicalAchievement) {
        if (practicalAchievement != null) {
            String possessorId = practicalAchievement.getPossessorId();
            String possessorName = practicalAchievement.getPossessorName();
            System.out.println(possessorName);
            String advisorId = practicalAchievement.getAdvisorId();
            String advisorName = practicalAchievement.getAdvisorName();
            possessorId = possessorId != null && !possessorId.equals("") ? stringUtils.parseJsonToString(possessorId) : possessorId;
            possessorName = possessorName != null && !possessorName.equals("") ? stringUtils.parseJsonToString(possessorName) : possessorName;
            advisorId = advisorId != null && !advisorId.equals("") ? stringUtils.parseJsonToString(advisorId) : advisorId;
            advisorName = advisorName != null && !advisorName.equals("") ? stringUtils.parseJsonToString(advisorName) : advisorName;
            practicalAchievement.setPossessorId(possessorId);
            practicalAchievement.setPossessorName(possessorName);
            practicalAchievement.setAdvisorId(advisorId);
            practicalAchievement.setAdvisorName(advisorName);
        }
        return practicalAchievement;
    }



}
